function A = gen_a(un, lambda, nx, ny)
% generates the A matrix.
% Note: v is a two element vector.
% for this to be generalized, v should be a passed in as two functions
% this functionality is not need for this assignment, so it was not
% implemented.
hx = 1/nx;
hy = 1/ny;
band1 = -(nx+1);
band2 = -1;
length = (nx+1)*(ny+1);
for k=1:length
    [i, j] = ij(k,nx);
    if (i==1)|(i==nx+1)|(j==1)|(j==ny+1)
        un(k) = 0;
    end
end
A = zeros((nx+1)*(ny+1));
for j=1:(ny+1)*(nx+1)
    if (j / (ny+1) <=1) | ((nx) <= j / (ny+1))
        A(j,j) = 1;
    else
        
        for i=1:(ny+1)*(nx+1)
            if (i / (nx+1) <=1) | ((ny) <= i / (nx+1)) |(mod(i,(nx+1))==0)|(mod(i,(nx+1))==1)
                A(i,i) =1;
                
            else 
                if i-j == -(nx+1)
                    A(i,j) = 1/hy^2;
                elseif i-j == -1
                    if mod(i,(nx+1))==0
                        A(i,j) = 0;
                    else
                        A(i,j) = 1/hx^2;
                    end
                elseif i-j == 0
                    A(i,j) = -2/hx^2 -2/hy^2 +lambda*(1 + 2*un(k));
                elseif i-j == 1
                    if mod(j,(nx+1))==0
                        A(i,j) = 0;
                    else
                        A(i,j) = 1/hx^2;
                    end
                elseif i-j == (nx+1)
                    A(i,j) = 1/hy^2;
                end
            end
        end
    end
end

        
        